package models

import (
	"time"
)

type Vip struct {
	ID    int       `json:"ID"`
	Img   string    `json:"Img"`
	Name  string    `json:"Name"`
	Phone string    `json:"Phone"`
	Types string    `json:"Types"`
	Price float64   `json:"Price"`
	Times time.Time `json:"Times"`
}

func MysqlList(page int, pageSize int, name string) ([]Vip, int64, error) {
	var vip []Vip
	var total int64
	query := DB.Model(&Vip{})
	if name != "" {
		query = query.Where("name like ?", "%"+name+"%")
	}
	if err = query.Count(&total).Error; err != nil {
		return nil, 0, err
	}
	if err = query.Order("id desc").Offset((page - 1) * pageSize).Limit(pageSize).Find(&vip).Error; err != nil {
		return nil, 0, err
	}
	return vip, total, nil
}
